<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>210-验证密码.html</title>
</head>
<body>
	<input type="text" id="txt" autocomplete="off">
	<button id="btn">检测</button>
</body>
<script>
	var oTxt = document.getElementById('txt');
	var oBtn = document.getElementById('btn');
	oBtn.onclick = function(){
		//以字母开头，长度在7～14之间，只能包含字母、数字和下划线;
		var sVal = oTxt.value;
		var reg =/^[a-zA-z]\w{5,11}$/;

		if(reg.test(sVal)){
			alert("合法");
		}else{
			alert("不合法");
		}
	}
</script>
</html>